package com.lifesting.wfs.Runtime.addon;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;

import com.lifesting.wfs.gd.DocumentRoot;
import com.lifesting.wfs.gd.GdPackage;
import com.lifesting.wfs.gd.ProcessDefinition;
import com.lifesting.wfs.gd.util.GdResourceFactoryImpl;

public class LocalProcessDefinitionLoader implements IProcessDefinitionLoader {

	@Override
	public ProcessDefinition load(String path) {
		URI file_uri = URI.createFileURI(path);
		ResourceSet rset = new ResourceSetImpl();
		rset.getPackageRegistry().put(GdPackage.eNS_URI, GdPackage.eINSTANCE);
		rset.getResourceFactoryRegistry().getExtensionToFactoryMap().put(GdPackage.eNAME,new GdResourceFactoryImpl());
		Resource res = rset.getResource(file_uri,true);
		DocumentRoot dr = (DocumentRoot) res.getContents().get(0);
		return dr.getProcess();
	}

}
